package com.xiaoyu.mem;

import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;

import com.xiaoyu.io.ByteOutStream;
import com.xiaoyu.objpool.ByteOutPool;

public class DirectMemory {
	protected static ByteBuffer alloc(int byteSize) {
		ByteBuffer buff = ByteBuffer.allocateDirect(byteSize);
		return buff;
	}

	public static void main(String[] args) throws IOException {
		ByteOutStream baos = null;
		DataOutputStream dos = null;
		try{
			baos = ByteOutPool.borrowObject();
			dos = new DataOutputStream(baos);
			dos.writeInt(123);
			dos.writeDouble(4.123);
			dos.flush();

			ByteBuffer buf = ByteBuffer.wrap(baos.toByteArray());
			System.out.println(buf.getInt());
			System.out.println(buf.getDouble());
		}finally{
			if(dos != null){
				dos.close();
			}
			if(baos != null){
				baos.close();
			}
		}
	}
}
